package processing;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import util.*;

public class CalculateScore {

	//return a hashtable with the list of documents and the weight the term has in it
	public Hashtable<String,Integer> CalculateTermWeightList(Entry entryFromInvIndex){
		
		//inverted DocFreq
		int idf     			      					 = entryFromInvIndex.getIdf(); 
		//hash of documents which contains the term with respective tf
		Hashtable<String,Integer> postingListWithTf      = new Hashtable<String,Integer>();
		//hash of documents which contains the term with respective tf-idf
		Hashtable<String,Integer> postingListWithWif     = new Hashtable<String,Integer>();
		List<String> aux = new ArrayList<String>();
		
		int Wif; // tf-idf weighting
		
		for (DocumentTermFrequency d : entryFromInvIndex.getDocTermFreqList()){
		
			aux.add(d.getDocPath());
			postingListWithTf.put(d.getDocPath(), d.getTf());
			
		};
		
		for (int i = 0 ; i< postingListWithTf.size() ; i++){
			
			Wif = CalculateTermWeight(idf,postingListWithTf.get(aux.get(i)));
			postingListWithWif.put(aux.get(i), Wif);
			
		};
		
		return postingListWithWif;
		
	};
	
	
	public int CalculateTermWeight(int idf, int tf){
		return (idf*tf);
	};
	
	public String CalculateSimilarity(Query q, InvertedIndex invIndex){
		Hashtable<String,Integer> QueryTokenWif = q.getTokensWifHash(invIndex);
		
		List<String> docIds = new ArrayList<String>();
		List<String> terms = new ArrayList<String>();
		List<Hashtable<String,Integer>> l;
		
		for (String s : q.getTokens()){
			
			terms.add(s);
			l.add(CalculateTermWeightList(invIndex.getEntry(s)));

		}
		
		
		
		
		
		
		
		
		return 0;
	};
	
		
	
}
